#!/bin/bash

# 设置CRLF
git config --global core.autocrlf input
git config --global core.safecrlf warn

# shrink
git repack -a -d --depth=250 --window=250

# 设置用户信息
git config --global user.name "Yulu Xu"
git config --global user.email "xuyulu86@126.com"

# 创建公钥
ssh-keygen -t rsa -C 'xuyulu86@126.com' -f ~/.ssh/github_id_rsa
ssh-keygen -t rsa -C 'xuyulu86@126.com' -f ~/.ssh/gitee_id_rsa

# create ssh config file
touch ~/.ssh/config
echo "#gitee" >> ~/.ssh/config
echo "Host gitee.com" >> ~/.ssh/config
echo "HostName gitee.com" >> ~/.ssh/config
echo "PreferredAuthentications publickey" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/gitee_id_rsa" >> ~/.ssh/config

echo "#github" >> ~/.ssh/config
echo "Host github.com" >> ~/.ssh/config
echo "HostName github.com" >> ~/.ssh/config
echo "PreferredAuthentications publickey" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/github_id_rsa" >> ~/.ssh/config

# wait for config pub rsa
echo '============================================================================'
echo '                                                                            '
echo '                                                                            '
echo '                                                                            '

cat ~/.ssh/gitee_id_rsa.pub | pbcopy
echo '请访问 https://gitee.com/profile/sshkeys 设置公钥. 设置完成后按任意键继续...'
read gitee

cat ~/.ssh/github_id_rsa.pub | pbcopy
echo '请访问 https://github.com/settings/keys 设置公钥. 设置完成后按任意键继续...'
read gitee

# verify
ssh -T git@gitee.com
ssh -T git@github.com

echo -n '请确认github和gitee已设置公钥. 设置完成后按任意键继续...'
read Arg
echo '                                                                            '
echo '                                                                            '
echo '                                                                            '
echo '                                                                            '
echo '============================================================================'
echo '=================================== Setup git success! ==================================='
